﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ClassLibrary.Entity;
using ClassLibrary.Data;

namespace ClassLibrary.DAO
{
    public class TblShippToDAO
    {
        private DBService _db = null;
        public TblShippToDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }
        public TblShippTo GetAll(int AccountID)
        {
            TblShippTo shippto = new TblShippTo();
            try
            {
                DataTable dt = _db.ExeSP_DataTable("select * from TblShipTo where CusID = @AccountID ",
                   new string[] { "@AccountID" },
                   new object[] { AccountID },
                  CommandType.Text);

                foreach (DataRow dr in dt.Rows)
                {
                    shippto.CusID = AccountID;
                    shippto.FName = dr["FName"].ToString();
                    shippto.LName = dr["LName"].ToString();
                    shippto.EmailAdress = dr["EmailAdress"].ToString();
                    shippto.MobilePhone = dr["MobilePhone"].ToString();
                    shippto.CusAddress = dr["CusAddress"].ToString();
                  
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return shippto;
        }
        public bool Update(TblShippTo shipto)
        {
            bool flag = false;
            try
            {
                int result = 0;
                result = _db.ExeSP_NonQuery("[sp_ShippingTo_Upd]",
                    new string[] { "@p_CusID", "@p_FName", "@p_LName","@p_CusAddress",
                         "@p_EmailAdress", "@p_MobilePhone" },
                    new object[] { shipto.CusID, shipto.FName, shipto.LName, shipto.CusAddress, shipto.EmailAdress, shipto.MobilePhone},
                    CommandType.StoredProcedure);

                flag = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

    }
}
